//
//  QXNLeftViewController.m
//  QuickDoctor
//
//  Created by sdos on 2017/3/8.
//  Copyright © 2017年 乔现宁. All rights reserved.
//

#import "QXNLeftViewController.h"
#import "Masonry.h"
#import "QXNLoginViewController.h"
#import "QXNRegisterViewController.h"

#define RGBColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1]

// 宏定义 随机颜色
#define RandomColor RGBColor(arc4random_uniform(255), arc4random_uniform(255), arc4random_uniform(255))


@interface QXNLeftViewController ()<UITableViewDelegate,UITableViewDataSource>

/*未登录界面*/
@property(nonatomic,strong)UIView *noLoginView;
/*登录界面*/
@property(nonatomic,strong)UIView *loginView;

/*tableView*/
@property(nonatomic,strong)UITableView *tableView;

@property(nonatomic,strong)NSArray *arr1;
@property(nonatomic,strong)NSArray *arr2;

@end

static NSString *identifier = @"hh";

@implementation QXNLeftViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupUI];
    
}

- (void)setupUI
{
    // 添加tableView
    UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    
    _tableView = tableView;
    
    tableView.dataSource = self;
    tableView.delegate = self;
    
    [self.view addSubview:tableView];
    
    // 注册cell
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    [self setupHeadView];
    
    //配置
    self.arr1 = @[@"名医通申请",@"病例管理",@"关注医生"];
    self.arr2 = @[@"设置与帮助",@"关于产品",@"分享给好友"];
   
}
#pragma mark
#pragma mark - 设置组头
- (void)setupHeadView
{
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 130)];
    headerView.backgroundColor = RGBColor(41, 188, 186);
    self.tableView.tableHeaderView = headerView;
    
    //头像
    UIImageView *imageView = [UIImageView new];
    imageView.image = [UIImage imageNamed:@"illness_img_person.png"];
    [headerView addSubview:imageView];
    
    //添加button
    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeSystem];
    [button1 setTitle:@"登录" forState:UIControlStateNormal];
    button1.tintColor = [UIColor whiteColor];
    [headerView addSubview:button1];
    
    UIButton *button2 = [UIButton buttonWithType:UIButtonTypeSystem];
    [button2 setTitle:@"注册" forState:UIControlStateNormal];
    button2.tintColor = [UIColor whiteColor];
    [headerView addSubview:button2];
    
    //点击事件
    [button1 addTarget:self action:@selector(clickLogin) forControlEvents:UIControlEventTouchUpInside];
    [button2 addTarget:self action:@selector(clickRegister) forControlEvents:UIControlEventTouchUpInside];
    
    //设置约束
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(headerView);
        make.width.height.mas_equalTo(60);
    }];
    [button1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(headerView.frame.size.width/2);
//        make.leading.bottom.equalTo(0);
        make.leading.offset(0);
        make.bottom.offset(-10);
    }];
    [button2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(headerView.frame.size.width/2);
//        make.trailing.bottom.equalTo(0);
        make.trailing.offset(0);
        make.bottom.offset(-10);
    }];
}


#pragma mark
#pragma mark - 点击跳转到登录/注册界面
- (void)clickLogin
{
    QXNLoginViewController *login = [[QXNLoginViewController alloc] init];
    [self.navigationController pushViewController:login animated:YES];
}
- (void)clickRegister
{
    QXNRegisterViewController *regist = [[QXNRegisterViewController alloc] init];
    [self.navigationController pushViewController:regist animated:YES];
}

//设置登录成功后显示的界面


#pragma mark
#pragma mark - 点击cell 进行跳转
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}


#pragma mark
#pragma mark -数据源方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    
    if (!cell) {
        
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    if (indexPath.section==0) {
        
        cell.textLabel.text = self.arr1[indexPath.row];
        
    }else{
        
        cell.textLabel.text = self.arr2[indexPath.row];
    }
    
    return cell;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}



@end
